//
// Created by Administrator on 2021/12/14.
//

#ifndef THREAD_CDB_POOL_HPP
#define THREAD_CDB_POOL_HPP
#include <condition_variable>
#include <memory>
#include <string>
#include <mutex>
#include <list>
// 连接池对象
class cdb_connect;
class cdb_pool : public std::enable_shared_from_this<cdb_pool>
{

public:
    static cdb_pool* getInstance(std::string pool_name, std::string db_server_ip, unsigned int db_server_port, std::string username,
                                  std::string password, std::string db_name,int max_connect);

public:
    cdb_pool();
    cdb_pool(std::string pool_name,std::string db_server_ip,unsigned int db_server_port,
             std::string username,std::string password,std::string db_name,int max_coonect);
    virtual ~cdb_pool();

public:
    void init();    // 初始化连接池

    std::string get_pool_name();
    std::string get_server_ip();

    std::string get_username();
    std::string get_dbname();
    std::string get_password();
    unsigned int get_server_port();
    int get_max_connect();
private:
    std::string m_pool_name;
    std::string m_server_ip;
    unsigned int m_server_port;
    std::string m_username;
    std::string m_db_name;
    std::string m_password;
    int m_db_cur_connect;
    int m_db_max_connect;
    // 最小连接和最大连接
    std::mutex m_mutex;
    std::condition_variable m_cond; // 条件变量
    bool m_request;
};


#endif //THREAD_CDB_POOL_HPP
